//
//  HomeTableViewCell.swift
//  YLH
//
//  Created by qinjiangtao on 2024/1/11.
//

import UIKit

class HomeTableViewCell: UITableViewCell {
    
    private var imgView = UIImageView()
    private var titleL = UILabel()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        addUI()
    }
    
    func addUI() {
        let bgView = UIView()
        bgView.frame = CGRect(x: 16, y: 10, width: SCREEN_WIDTH - 32, height: 160)
        bgView.backgroundColor = .white
        bgView.addRoundedCorners(withRadius: 10)
        contentView.addSubview(bgView)
        
        imgView = UIImageView().then {
            $0.frame = CGRect(x: 0, y: 0, width: SCREEN_WIDTH - 32, height: 160)
            $0.image = UIImage(named: "")
            $0.contentMode = .scaleAspectFill
            $0.clipsToBounds = true
            $0.addRoundedCorners(withRadius: 10)
        }
        bgView.addSubview(imgView)
        
        titleL = UILabel().then({
            $0.frame = CGRect(x: 0, y: 118, width: imgView.width, height: 42)
            $0.backgroundColor = UIColor(white: 0, alpha: 0.4)
            $0.text = ""
            $0.textColor = .white
            $0.font = SYSFONT(ofSize: 18)
            $0.addRoundedCorners(withRadius: 10, byRoundingCorners: [.bottomLeft, .bottomRight])
        })
        bgView.addSubview(titleL)
        
    }
    
    var model = HomeListModel() {
        didSet {
            titleL.text = " \(model.name)"
            imgView.kf.setImage(with: URL(string: "\(IMAGE_URL)\(model.image)"), placeholder: UIImage(named: "\(model.name)H"))
        }
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
